package xyz.zhouzhaodong.crm.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import xyz.zhouzhaodong.crm.interceptor.TokenInterceptor;

import java.util.ArrayList;
import java.util.List;

/**
 * 拦截器配置
 * @author zhouzhaodong
 */
@Configuration
public class IntercepterConfig implements WebMvcConfigurer {

    private final TokenInterceptor tokenInterceptor;

    /**
     * 构造方法
     * @param tokenInterceptor
     */
    public IntercepterConfig(TokenInterceptor tokenInterceptor){
        this.tokenInterceptor = tokenInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        List<String> excludePath = new ArrayList<>();
        // 注册
        excludePath.add("/staff/register");
        // 登录
        excludePath.add("/staff/login");
        // 静态资源
        excludePath.add("/static/**");
        // 上传下载操作
        excludePath.add("/material/**");

        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);

    }

}
